package demo1;
class Student {
    //私有属性name
    private String name = "bit";
    //公有属性age
    public int age = 18;
    //不带参数的构造⽅法
    public Student(){
        System.out.println("Student()");
    }
    private Student(String name,int age) {
        this.name = name;
        this.age = age;
        System.out.println("Student(String,name)");
    }
    private void eat(){
        System.out.println("i am eat");
    }
    public void sleep(){
        System.out.println("i am pig");
    }
    private void function(String str) {
        System.out.println(str);
    }
    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class Testdemo {
    public static void main(String[] args) {
        //获得class对象的三种方式
        //1、Class.forName("累的全路径名"),同时也是最常用的
        Class c1=null;
        try {
            //c1=Class.forName("Student");//这里容易出问题，若在包底下需要加上包
            c1=Class.forName("demo1.Student");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException();
        }

        //2、使用.Class方法
        Class c2=Student.class;

        //3、使用getClass方法
        Student S=new Student();
        Class c3=S.getClass();


//        ⼀个类在 JVM 中只会有⼀个 Class 实例, 即我们对上⾯获取的c1,c2,c3进⾏ equals ⽐较，发现都是true
        System.out.println(c1.equals(c2));
        System.out.println(c1.equals(c3));
        System.out.println(c2.equals(c3));
    }
}
